package com.gbx.ximalayating.fragment;


import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.gbx.ximalayating.R;
import com.gbx.ximalayating.entity.RecommendOne;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class DiscoveryColumnsFragment extends Fragment {


    public DiscoveryColumnsFragment() {
        // Required empty public constructor
    }

    public static DiscoveryColumnsFragment getInstance(List<RecommendOne.DiscoveryColumns.ConEntity> list) {
        DiscoveryColumnsFragment fragment = new DiscoveryColumnsFragment();
        Bundle bundle = new Bundle();
        bundle.putParcelableArrayList("list", (ArrayList<? extends Parcelable>) list);
        fragment.setArguments(bundle);
        return fragment;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_discovery_columns, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        List<RecommendOne.DiscoveryColumns.ConEntity> list = getArguments().getParcelableArrayList("list");
        ImageView image1 = (ImageView) view.findViewById(R.id.disColumns_image1);
        ImageView image2 = (ImageView) view.findViewById(R.id.disColumns_image2);
        ImageView image3 = (ImageView) view.findViewById(R.id.disColumns_image3);
        ImageView image4 = (ImageView) view.findViewById(R.id.disColumns_image4);
        TextView text1 = (TextView) view.findViewById(R.id.disColumns_text1);
        TextView text2 = (TextView) view.findViewById(R.id.disColumns_text2);
        TextView text3 = (TextView) view.findViewById(R.id.disColumns_text3);
        TextView text4 = (TextView) view.findViewById(R.id.disColumns_text4);
        Picasso.with(getContext()).load(list.get(0).getCoverPath()).into(image1);
        Picasso.with(getContext()).load(list.get(1).getCoverPath()).into(image2);
        Picasso.with(getContext()).load(list.get(2).getCoverPath()).into(image3);
        Picasso.with(getContext()).load(list.get(3).getCoverPath()).into(image4);
        text1.setText(list.get(0).getTitle());
        text2.setText(list.get(1).getTitle());
        text3.setText(list.get(2).getTitle());
        text4.setText(list.get(3).getTitle());
    }
}
